/**
 * 签到组件
 */
class SignItem extends BaseComp{
    private img_icon:eui.Image;
    private img_mask:eui.Image;
    private img_had:eui.Image;
    private lb_day:eui.Label;
    private lb_award:eui.Label;
    private title_tody:eui.Image;
    private img_bg_di_2:eui.Image;
    private img_bg_di:eui.Image;
    private img_light:eui.Image;

    constructor(data?)
    {
        super('SignItemView',data)
    }

    public init()
    {
        this.updateUI();
    }

    public updateUI()
    {
        if(this.data)
        { 
            let day:number = this.data.id;
            
            this.lb_day.text = '第'+ GameConst.ChineseNum[day] + '天';
            let round = this.data.round;
            this.title_tody.visible = false;
            // this.lb_sign.text = StringUtil.getSwfLangStrVar('sign_1',[day+'']);
 
            let info = ResourceUtil.instance().parseSignAward(this.data['award'+round], day);
            if(info)
            {
                if(round == 1 && day == 7)
                {
                    this.img_icon.source = 'sign_award';
                }
                else
                {
                    this.img_icon.source = info.icon;
                }
                let heght = 61;
                this.img_icon.width = this.img_icon.width * (heght / this.img_icon.height);
                this.img_icon.height = 61;
                if(info.num != 0)
                    this.lb_award.text = info.desc + 'x' + info.num;
                else
                    this.lb_award.text = info.desc;
            }
            let curSignDay = RoleCache.instance().signDays;
            if(curSignDay <= day)
            {
                //尚未签到
                // this.addAlphaDraw();
                this.img_mask.visible = false;
                this.img_had.visible = false;
                
            }
            else
            {
                this.signHandle();
            }
                      
            if(curSignDay == day)
            {
                this.title_tody.visible = true;
                this.img_bg_di_2.visible = false;
                this.lb_day.visible = false;
                if(this.data.isSign)
                {
                    this.signHandle();
                }
                else
                {
                    this.img_light.visible = true;
                    this.img_bg_di.source = 'blue_di';
                    this.img_bg_di_2.source = 'day_di_1';
                }
            }
        }
    }

    public signHandle()
    {
        this.img_mask.visible = true;
        this.img_had.visible = true;
        this.img_bg_di.source = 'blue_di';
        this.img_bg_di_2.source = 'day_di_1';
    }

    public addAlphaDraw()
    {
        //添加渲染矩阵
        ShaderUtil.ImgDark(this.img_icon, -40);
    }

    public updateSelf()
    {
        this.data.isSign = 1;
        this.init();
    }

    public clear()
    {
        super.clear();
        this.img_icon.filters = null;
    }
}

window['SignItem'] = SignItem;